home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
datebox.exe
/
DATEBOX.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-07-07
|
38KB
|
1,101 lines
unit datebox;
(*****************************
Most parts of this unit were imported from Borland libraries
(I'm R.Regez on GEnie and 100014,2516 on CompuServe) and adapted
to my needs: 90/7.7.91.
Many thanks to Gerald Rohr (GENIE G.ROHR), who writes in his TPWIO.PAS:
"Much credit is due Bill Meacham who wrote the original file IO22.INC
and released it to the public domain. Using that work this unit was
created and added to by Gerald Rohr of Homogenized Software. As
with Bill's work, this program is released to the Public Domain for
all to use and modify."
Same to Rick Amerson (uploaded to GENIE by R.WERT) whose TURBO CALENDAR FUNCTIONS
(Module version 1.01A; CALENDAR.PAS) inspired me to look around for the
"ultimate date unit"!
Last to join was Charles B. Chapman (CompuServe 74370,516, whose DAYFEASTER has
been integrated, and whose Julian/Gregorian Routines seem to be the most
sophisticated, at least, I understand them least...
I have added JulianDay and JulianDaytoDate without integrating them.
Should I use them?
Using Rick Amerson's ideas, I added COUNTDAYS which extracts dates from
INT's or LONGINT's which bear dates computed to a given baseyear (between
1901-2100). I needed that to access a broad Swiss stock market database
where the dates are "hidden" in INT's as differences to 1.1.1976 (without
taking notice of leapyears! The functions to correct that are part of a
separate unit). An illustration of this concept is in FAR_DATE,
which returns the n-days in the future or in the past (-) lying date,
relative to any date.
A little bug in DAYOFWEEK (G.Rohr's ZELLER) has been corrected (?); the
function returned some negative numbers in the years outside 1925-1999.
An alternative by Charles B. Chapman has been added (as commentary), it
seems to return identical values. And old Julius would rotate in his grave
if he knew, that I'm calculating leapyears in "his" part of the calendar...
Dear anglosaxons: Please don't use set types with text! If I try
to adapt your programs to German or French, the chars above ASCII 127
kill Turbo Pascal's compiler (syntax error 5)!
Examples: your set type monthname=(January,February,March...)
translates to German as: Monat_Name=(Januar,Februar,März..) (ASCII 132)
to French as: nom_du_mois=(Janvier,Février...) (ASCII 130)
You would not build set types with japanese chars, would you?
Another problem is the format: Nobody here uses MM/DD/(CC)YY, just
DD/MM/(CC)YY is common. Does "go metrics" in USA and UK solve this?
At least, an USDATETEXT(), which calls DATETEXT() and cuts and pastes
the resulting date-string, should be possible. Or should one try to
link this format problem with the "language" switch?
....and, dear anglosaxons: you might find my use of your language
disturbing, please don't hesitate to inform me about the most terrible
mistakes...
Rudolf Regez, CH-8952 Schlieren,Switzerland.
*****************************)
INTERFACE
uses dos,crt,KEYBRD;
{ KEYBRD is my I/O-unit; just remove it's reference and the brackets
below, and keytype, keysettype and key will work standalone}
{
type
keytype = (NullKey,CarriageReturn,TabKey,BackspaceKey,RightArrow,
LeftArrow,DelKey,InsertKey,HomeKey,EndKey,TextKey,NumberKey,
SpaceKey,EscapeKey);
keySetType = set of keyType;
var key:keytype;
}
var baseyear:longint; {range: 1901<= baseyear <=2100}
language:integer;
{0: english; german:1; french:2; italian:3}
sysdatetime:datetime; {Never use sysdatetime directly in procedures
or functions, it could get changed!}
sysdate_str,sysdate10_str:string;
separator:char;
datekey:keytype;
FUNCTION datetext(buf_dt:datetime;long:integer):string;
{ returns a string of the dates to print, returns different date formats
dependent upon value of long and in the language set with the
global variable "language" (default: German, of course, set in the
initialization part of this unit)}
{ values of long: 8 -> 02.09.91
10 -> 02.09.1991
add 10 to eliminate leading zero's 18(20) -> 2.9.(19)91
add 100 to get 'Mon, (D)D.(M)M.(YY)YY' format
add 1000 to get 'Monday (D)D. September (YY)YY' format
add 10000 to get 'Monday (D)D. Sep. (YY)YY' format }
PROCEDURE read_date (var date_str:string;var dt:datetime;var key:keytype);
{reads date from keyboard after last cursor position and tests it
if incoming date_str is not empty and if correct this serves als default}
FUNCTION check_date (var date_str:string):boolean;
{tests a string-date}
FUNCTION longdat_from_dt(newdt:datetime):longint;
{transforms datetime format into Longint CCYYMMDD ie 19911231}
PROCEDURE dt_from_longdat(newdt_long : longint;var new_dt:datetime);
{G. Rohr's get_dt_val; transforms Longint CCYYMMDD ie 19911231 into
datetime format}
FUNCTION equal_date(dt1, dt2 : datetime) : boolean; {Gerald Rohr}
{ Tests whether two dates are equal }
FUNCTION weekend(dt:datetime):boolean; {Rudolf Regez}
PROCEDURE dt_from_stringdat(var s:string;var dt:datetime); {Rudolf Regez}
{ converts date-string into datetime-date}
FUNCTION date_diff(dt1, dt2 : datetime) : longint; {Gerald Rohr}
{ computes the number of days between two dates }
PROCEDURE next_day(var dt : datetime); {Gerald Rohr}
{ Adds one day to the date }
PROCEDURE next_workingday(var dt : datetime); {Rudolf Regez}
{ Seeks next working day }
PROCEDURE prev_day(var dt : datetime); {Gerald Rohr}
{ Subtracts one day from the date }
PROCEDURE prev_workingday(var dt : datetime); {Rudolf Regez}
{ Seeks prev working day }
FUNCTION far_date(var dt:datetime;d:longint):string; {Rudolf Regez}
{..a more general next_/prev_day-routine}
PROCEDURE Today; {Rick Amerson}
{puts system date & time (time when unit is initialized) in the global
SYSDATETIME (DateTime) and returns the SYSDATE_STR-string}
FUNCTION countdays_into_dt (d:longint;var dt:datetime):string; {Rudolf Regez}
{converts d days from BASEYEAR, where: 1901<=BASEYEAR<=2100, in a
DATE10_STR; valid date range: 1.1.0004<=DATE<=???? (at least 5101!)
When DATE_DIFF is used to compute the days, add 1 day to include the starting
point: d:=DATE_DIFF(baseyear_date,DATE)+1 to get the same date DATE back
from DAYS_SINCE(d); BASEYEAR must be: 1.1.BASEYEAR,
where: 1901<=BASEYEAR<=2100; example in FAR_DATE. I need that
to read a compressed tw byte date from a large database which contains Swiss Stock Market prices}
FUNCTION count_days(dt:datetime):longint; {Rudolf Regez}
{calculate number of days from 1.1.BASEYEAR; the result fed as "d" into
COUNTDAYS_INTO_DT should return same dt}
FUNCTION count_intdays(dt:datetime):integer; {Rudolf Regez}
{calculate INTEGER number of days from 1.1.BASEYEAR; the result fed as "d" into
COUNTDAYS_INTO_DT should return same dt. LIMIT: 32767, of course! I need that
to write a compressed tw byte date to a large database which contains
Swiss Stock Market prices}
FUNCTION leapyear(yr:word):boolean; {Gerald Rohr}
{ Whether the year is a leap year or not.
The year is year and century, e.g. year '1984' is 1984, not 84 }
PROCEDURE DateOfEaster (Yr : WORD; VAR Mo, Da : WORD); {Charles B. Chapman}
IMPLEMENTATION
type
juldate = record
yr : longint ; { 0 .. 9999 }
day : longint ; { 1 .. 366 }
end;
str10=string[10];
montharray = array [1 .. 13] of integer ;
monthnamedef=array[1..48] of str10;
daynamedef=array[0..27] of str10;
const
dayname:daynamedef =('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday',
'Sonntag','Montag','Dienstag','Mittwoch',
'Donnerstag','Freitag','Samstag',
'Dimanche','Lundi','Mardi','Mercredi',
'Jeudi','Vendredi','Samedi',
'Domenica','Lunedi','Martedi','Mercoledi',
'Giovedi','Venerdi','Sabato');
monthname:monthnamedef = ('Jan